﻿namespace Sidvall.UI.Messaging
{
    public class BusyContext
    {
        #region Public Members

        public string Message { get; set; }
        public string Scope { get; set; }

        #region Create

        public static BusyContext Create(string message, string scope)
        {
            return new BusyContext()
            {
                Message = message,
                Scope = scope,
            };
        }

        #endregion
        #region Deserialize

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        public static BusyContext Deserialize(string context)
        {
            return Sidvall.Serialization.SerializerManager.Current.TryDeserialize<BusyContext>(context, () =>
            {
                return new BusyContext();
            });
        }

        #endregion
        #region Serialize

        public string Serialize()
        {
            return Serialize(this);
        }
        public static string Serialize(BusyContext context)
        {
            return Sidvall.Serialization.SerializerManager.Current.SerializeObject(context);
        }
        public static string Serialize(string message, string scope)
        {
            var item = Create(message, scope);
            return Serialize(item);
        }

        #endregion

        #endregion
    }
}
